package com.itheima.service.impl;

import com.itheima.dao.GoodsDao;

import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.Goods;
import com.itheima.service.GoodsService;
import com.itheima.utils.MapperUtil;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.logging.Logger;

/**
 * @author ：spt
 * @date ：Created in 2020/12/14
 * @description ：
 * @version: 1.0
 */
public class GoodsServiceImpl implements GoodsService {


    private GoodsDao goodsDao = MapperUtil.getMapper(GoodsDao.class);
    @Override
    public PageResult pageQuery(QueryPageBean param) {
        System.out.println("[商品-分页查询]param:"+param);

        // 查询数据列表 limit offset,pageSize
        int offset = (param.getCurrentPage() - 1) * param.getPageSize();
        List<Goods> goods = goodsDao.selectByPage( offset,param.getPageSize());
        // 查询总数据条数
        Long  count = goodsDao.countAll();
        return new PageResult(count,goods);
    }

    @Override
    public int add(Goods goods) {
        System.out.println("[商品-添加]data:"+goods);
        return goodsDao.insert(goods);
    }

    @Override
    public int deleteById(Integer id) {
        System.out.println("[商品-删除]id:"+id);
        return goodsDao.deleteById(id);
    }
}
